home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / DefaultListModel.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  230 lines

  1. /*
  2.  * @(#)DefaultListModel.java    1.13 98/02/12
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. import java.util.Vector;
  24. import java.util.Enumeration;
  25.  
  26. import com.sun.java.swing.event.*;
  27.  
  28.  
  29. /**
  30.  * This class implements the java.util.Vector API and notifies
  31.  * the JListDataModel listeners when changes occur.  Presently
  32.  * it delegates to a Vector, in a future release it will be
  33.  * a real Collection implementation.
  34.  * <p>
  35.  * Warning: serialized objects of this class will not be compatible with
  36.  * future swing releases.  The current serialization support is appropriate 
  37.  * for short term storage or RMI between Swing1.0 applications.  It will
  38.  * not be possible to load serialized Swing1.0 objects with future releases
  39.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  40.  * baseline for the serialized form of Swing objects.
  41.  *
  42.  * @version 1.13 02/12/98
  43.  * @author unknown
  44.  */
  45.  
  46. public class DefaultListModel extends AbstractListModel
  47. {
  48.     private Vector delegate = new Vector();
  49.  
  50.     public int getSize() {
  51.     return delegate.size();
  52.     }
  53.  
  54.     public Object getElementAt(int index) {
  55.     return delegate.elementAt(index);
  56.     }
  57.  
  58.     public void copyInto(Object anArray[]) {
  59.     delegate.copyInto(anArray);
  60.     }
  61.  
  62.     public void trimToSize() {
  63.     delegate.trimToSize();
  64.     }
  65.  
  66.     public void ensureCapacity(int minCapacity) {
  67.     delegate.ensureCapacity(minCapacity);
  68.     }
  69.  
  70.     public void setSize(int newSize) {
  71.     int oldSize = delegate.size();
  72.     delegate.setSize(newSize);
  73.     if (oldSize > newSize) {
  74.         fireIntervalRemoved(this, newSize, oldSize-1);
  75.     }
  76.     else if (oldSize < newSize) {
  77.         fireIntervalAdded(this, oldSize, newSize-1);
  78.     }
  79.     }
  80.  
  81.     public int capacity() {
  82.     return delegate.capacity();
  83.     }
  84.  
  85.     public int size() {
  86.     return delegate.size();
  87.     }
  88.  
  89.     public boolean isEmpty() {
  90.     return delegate.isEmpty();
  91.     }
  92.  
  93.     public Enumeration elements() {
  94.     return delegate.elements();
  95.     }
  96.  
  97.     public boolean contains(Object elem) {
  98.     return delegate.contains(elem);
  99.     }
  100.  
  101.     public int indexOf(Object elem) {
  102.     return delegate.indexOf(elem);
  103.     }
  104.  
  105.     public int indexOf(Object elem, int index) {
  106.     return delegate.indexOf(elem, index);
  107.     }
  108.  
  109.     public int lastIndexOf(Object elem) {
  110.     return delegate.lastIndexOf(elem);
  111.     }
  112.  
  113.     public int lastIndexOf(Object elem, int index) {
  114.     return delegate.lastIndexOf(elem, index);
  115.     }
  116.  
  117.     public Object elementAt(int index) {
  118.     return delegate.elementAt(index);
  119.     }
  120.  
  121.     public Object firstElement() {
  122.     return delegate.firstElement();
  123.     }
  124.  
  125.     public Object lastElement() {
  126.     return delegate.lastElement();
  127.     }
  128.  
  129.     public void setElementAt(Object obj, int index) {
  130.     delegate.setElementAt(obj, index);
  131.     fireContentsChanged(this, index, index);
  132.     }
  133.  
  134.     public void removeElementAt(int index) {
  135.     delegate.removeElementAt(index);
  136.     fireIntervalRemoved(this, index, index);
  137.     }
  138.  
  139.     public void insertElementAt(Object obj, int index) {
  140.     delegate.insertElementAt(obj, index);
  141.     fireIntervalAdded(this, index, index);
  142.     }
  143.  
  144.     public void addElement(Object obj) {
  145.     int index = delegate.size();
  146.     delegate.addElement(obj);
  147.     fireIntervalAdded(this, index, index);
  148.     }
  149.  
  150.     public boolean removeElement(Object obj) {
  151.     int index = indexOf(obj);
  152.     boolean rv = delegate.removeElement(obj);
  153.     if (index > 0) {
  154.         fireIntervalRemoved(this, index, index);
  155.     }
  156.     return rv;
  157.     }
  158.  
  159.  
  160.     public void removeAllElements() {
  161.     int index1 = delegate.size()-1;
  162.     delegate.removeAllElements();
  163.     if (index1 >= 0) {
  164.         fireIntervalRemoved(this, 0, index1);
  165.     }
  166.     }
  167.  
  168.  
  169.     public String toString() {
  170.     return delegate.toString();
  171.     }
  172.  
  173.  
  174.     /* The remaining methods are included for compatibility with the
  175.      * JDK1.2 Vector class.
  176.      */
  177.  
  178.     public Object[] toArray() {
  179.     Object[] rv = new Object[delegate.size()];
  180.     delegate.copyInto(rv);
  181.     return rv;
  182.     }
  183.  
  184.     public Object get(int index) {
  185.     return delegate.elementAt(index);
  186.     }
  187.  
  188.     public Object set(int index, Object element) {
  189.     Object rv = delegate.elementAt(index);
  190.     delegate.setElementAt(element, index);
  191.     fireContentsChanged(this, index, index);
  192.     return rv;
  193.     }
  194.  
  195.     public void add(int index, Object element) {
  196.     delegate.insertElementAt(element, index);
  197.     fireIntervalAdded(this, index, index);
  198.     }
  199.  
  200.     public Object remove(int index) {
  201.     Object rv = delegate.elementAt(index);
  202.     delegate.removeElementAt(index);
  203.     fireIntervalRemoved(this, index, index);
  204.     return rv;
  205.     }
  206.  
  207.     public void clear() {
  208.     int index1 = delegate.size()-1;
  209.     delegate.removeAllElements();
  210.     if (index1 >= 0) {
  211.         fireIntervalRemoved(this, 0, index1);
  212.     }
  213.     }
  214.  
  215.     public void removeRange(int fromIndex, int toIndex) {
  216.     for(int i = toIndex; i >= fromIndex; i--) {
  217.         delegate.removeElementAt(i);
  218.     }
  219.     fireIntervalRemoved(this, fromIndex, toIndex);
  220.     }
  221.  
  222.     /*
  223.     public void addAll(Collection c) {
  224.     }
  225.  
  226.     public void addAll(int index, Collection c) {
  227.     }
  228.     */
  229. }
  230.